// src/views/home/index.tsx
import React, { useEffect, useState } from 'react';
import { Button, Col, Row, Statistic } from 'antd';
import axios from 'axios';
import { valueType } from 'antd/lib/statistic/utils';

type IndexProps = {}

// let sum :any


const Home: React.FC = (props: IndexProps) => {
  const [products, setProducts] = useState(0);
  const [users, setUsers] = useState(0);
  // 获取商品信息
  const drinksCount = async () => {
    await axios({
      url: "http://localhost:12580/production",
      method: "get"
    })
      .then(res => {
        console.log("product=", res)
        setProducts(res.data.length)

      })
  }
  // 获取用户信息
  const userCount = async () => {
    await axios({
      url: "http://localhost:12580/user",
      method: "get"
    })
      .then(res => {
        console.log("users=", res)
        setUsers(res.data.length)

      })
  }
  useEffect(() => {
    drinksCount();
    userCount()
  }, [])

  return (
    <>
      <Row gutter={16}>
        <Col span={12}>
          <Statistic title="用户数量" value={users} />
        </Col>
        <Col span={12}>
          <Statistic title="商品数量" value={products} precision={0} />
          <Button style={{ marginTop: 16 }} type="primary" onClick={() => {
            drinksCount();
            userCount();
          }} >
            刷新
          </Button>
        </Col>

      </Row>
    </>
  )

};

export default Home;